<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>保险产品管理</el-breadcrumb-item>
      <el-breadcrumb-item>修改保险产品</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card>
      <el-form label-width="80px">
        <h3>修改保险产品</h3>
        <el-col :span="11">
          <el-form-item label="保险编号">
            <el-input v-model.lazy="changeForm._id" :disabled="true"></el-input>
          </el-form-item>
          <el-form-item label="保险名称">
            <el-input v-model.lazy="changeForm.name"></el-input>
          </el-form-item>
          <el-form-item label="投保金额">
            <el-input v-model.lazy="changeForm.price"></el-input>
          </el-form-item>
          <el-form-item label="赔付金额">
            <el-input v-model.lazy="changeForm.payment"></el-input>
          </el-form-item>
          <el-form-item label="有效时间">
            <el-input v-model.lazy="changeForm.duration"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="change">确认修改</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-card>
    <!-- 卡片视图 -->
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions, mapState, mapMutations } = createNamespacedHelpers(
  "insurances"
);
export default {
  data() {
    return {
      changeForm: {
        name: "",
        price: "",
        payment: "",
        duration: "",
      },
    };
  },

  created() {
    const _id = this.$route.params._id;
    this.getInsuranceById(_id);
  },

  computed: {
    ...mapState(["update"]),
  },

  watch: {
    update(val) {
      this.changeForm = val;
    },
  },

  methods: {
    ...mapActions(["getInsuranceById", "modifyInsurance"]),
    change() {
      this.modifyInsurance(this.changeForm);
      this.$router.push("/productlist");
    },
  },
};
</script>

<style>
</style>